package com.ruoyi.web.controller.CollectController;

import com.ruoyi.system.domain.ZhyCollect;
import com.ruoyi.system.domain.vo.Results;
import com.ruoyi.system.service.ZhyCollectService;
import com.ruoyi.web.controller.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ZHYCollectController {
    @Autowired
    private ZhyCollectService ZhycollectServices;
    @PostMapping("/selectCollect")
    public R<List<ZhyCollect>> select(@RequestBody ZhyCollect zhyCollect)
    {
        List<ZhyCollect> zhyCollects = ZhycollectServices.selectByuserid(zhyCollect);
        return  R.success(zhyCollects.size(),zhyCollects);
    }
    @PostMapping("/addCollect")
    public  R<String> addCollect(@RequestBody ZhyCollect zhyCollect)
    {
        int i = ZhycollectServices.addCollect(zhyCollect);
        if(i ==0)
            return R.error("添加失败");
        return R.success(1,"添加成功");
    }
    @PostMapping("/delete")
    public R<String> delete(@RequestBody ZhyCollect zhyCollect)
    {
        int i = ZhycollectServices.deleteCollect(zhyCollect);
           if(i==0)
               return R.error("删除失败");
           return  R.success(1,"删除成功");
    }
    @PostMapping("/selectCollectByid")
    public Results selectByid(@RequestBody ZhyCollect zhyCollect)
    {
        ZhyCollect zhyCollect1 = ZhycollectServices.selectByid(zhyCollect);
           if(zhyCollect1==null)
               return new Results(400,"",false);
        return new Results(400,"",true);
    }
}
